#include "file.h"

static configDataT configData;

void readFromFile(void){
	FILE *file;
	
	configData = New(configDataT);
	
	configData->fileName = "webconfig.txt";

	file = fopen(configData->fileName, "r");
	
	
	configData->httpPort = StringToInteger(ReadLine(file));
	configData->telnetPort = StringToInteger(ReadLine(file));
	configData->directory = ReadLine(file);
	configData->logDir = ReadLine(file);
	configData->password = ReadLine(file);

	fclose(file);
}

webConfigDataStruct getConfigData(void){
	return *configData;
}

void saveToFile(void){
	FILE *file;

	file = fopen(configData->fileName, "w");

	fprintf(file, "%d\n", getHTTPPort());
	fprintf(file, "%d\n", getTelnetPort());
	fprintf(file, "%s\n", getRootDir());
	fprintf(file, "%s\n", getLogDir());
	fprintf(file, "%s\n", getPassword());

	fclose(file);
}

int getHTTPPort(void){
	return configData->httpPort;
}

int getTelnetPort(void){
	return configData->telnetPort;
}

string getRootDir(void){
	return configData->directory;
}

string getLogDir(void){
	return configData->logDir;
}

string getPassword(void){
	return configData->password;
}